package meng.study.jaxb.demo;

import java.util.Date;

import meng.study.jaxb.entity.Head;
import meng.study.jaxb.entity.User;
import meng.study.jaxb.utils.XMLUtil;

public class JaxbDemo {

	public static void objToXml() {
		User user = new User();
		user.setId(1);
		user.setName("张三");
		user.setBir(new Date());
		user.setWeight(55.8);

		Head head = new Head();
		head.setEye("eye2");
		head.setFace("face2");
		head.setMouth("mouth1");
		user.setHead(head);

		String result = XMLUtil.convertToXml(user);
		System.out.println(result);
	}

	public static void xmlToObj() {
		String xmlStr = "<user><id>1</id><bir>2018-01-08T15:54:10.311+08:00</bir><weight>55.8</weight><head><eye>eye2</eye><er>er</er><face>face2</face><mouth>mouth1</mouth></head></user>";
		User user = (User) XMLUtil.convertXmlStrToObject(User.class, xmlStr);
		System.out.println(user);
	}
}
